package edu.berkeley.cs160.GroupC.views;

import edu.berkeley.cs160.GroupC.R;
import edu.berkeley.cs160.GroupC.WorkoutMusicApplication;
import edu.berkeley.cs160.GroupC.songs.Song;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.TouchDelegate;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;


public class PlaylistItem extends LinearLayout{
	
	private CheckBox checkbox;
	private TextView album;
	private TextView title;
	private TextView artist;
	private TextView gap;
	private Song song;
	private TextView bpmText;
	
	public PlaylistItem(Context context, AttributeSet attr) {
		super(context, attr);
	}

	public void addSong(Song song) {
		
		checkbox = (CheckBox) findViewById(R.id.songsCheck);
		checkbox.setFocusable(false);
		checkbox.setFocusableInTouchMode(false);
		checkbox.setChecked(song.isInPlaylist());
		
		album = (TextView) findViewById(R.id.songsAlbum);
		album.setFocusable(false);
		album.setFocusableInTouchMode(false);
		
		title = (TextView) findViewById(R.id.songsTitle);
		title.setFocusable(false);
		title.setFocusableInTouchMode(false);
		
		artist = (TextView) findViewById(R.id.songsArtist);
		artist.setFocusable(false);
		artist.setFocusableInTouchMode(false);
		
		bpmText = (TextView) findViewById(R.id.songsBpm);
		int curBpm = song.getBpm();
		
		if( curBpm != -1){
			bpmText.setText("bpm: "+curBpm);
			
			switch (song.getRating()){
				case WorkoutMusicApplication.LOW_INTENSITY: 
					bpmText.setTextColor(0xFF33FF00);
					break;
				case WorkoutMusicApplication.MEDIUM_INTENSITY:
					bpmText.setTextColor(0xFFFFFF00); 
					break;
				case WorkoutMusicApplication.HIGH_INTENSITY:
					bpmText.setTextColor(0xFFFF0000); 
					break;
				default:
					bpmText.setTextColor(0);
					break;
						
			}
			
		}else
		{
			bpmText.setText("bpm: ?");
			bpmText.setTextColor(0xFF000000);
		}
		
		
		
		Log.v("ASA", "PlaylistItem: addSong, start");
		this.song = song;
		Log.v("ASA", "PlaylistItem: addSong, setting album...");
		Log.v("ASA", "PlaylistItem: album - "+song.getAlbum());
		album.setText(song.getAlbum());
		Log.v("ASA", "PlaylistItem: addSong, setting artist...");
		artist.setText(song.getArtist());
		Log.v("ASA", "PlaylistItem: addSong, setting title...");
		title.setText(song.getTitle());
		Log.v("ASA", "PlaylistItem: addSong, setting checked...");
		checkbox.setChecked(song.isInPlaylist());
		Log.v("ASA", "PlaylistItem: constructor, end");
	}

	public Song getSong() {
		return song;
	}
	
	protected void onFinishInflate(){
		super.onFinishInflate();
	}
	
}
